﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class MapService : IIndoorMapService
    {

        public IndoorPositionMap RetrieveMapData()
        {
            return CreateTestMap();
        }

        private string Base64Encode(byte[] data)
        {
            return System.Convert.ToBase64String(data);
        }

        private string Base64Encode(string str)
        {
            byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(str);
            return Base64Encode(bytes);
        }

        public IndoorPositionMap CreateTestMap()
        {
            string imagePath = (string) System.Configuration.ConfigurationManager.AppSettings["imageFileName"];
            string dslPath = (string) System.Configuration.ConfigurationManager.AppSettings["dslScriptName"];
            return new IndoorPositionMap()
            {
                ImageData = Base64Encode(System.IO.File.ReadAllBytes(imagePath)),
                DSLScript = Base64Encode(System.IO.File.ReadAllBytes(dslPath)),
                StructureInformation = new IndoorStructure()
                {
                    Walls = new List<Wall>()
                    {
                        new Wall() 
                        {
                            StartPosition = new Position() { X = 0, Y = 0 },
                            EndPosition = new Position() { X = 10, Y = 0 }
                        },
                        new Wall() 
                        {
                            StartPosition = new Position() { X = 10, Y = 0 },
                            EndPosition = new Position() { X = 10, Y = 10 }
                        },
                        new Wall() 
                        {
                            StartPosition = new Position() { X = 10, Y = 10 },
                            EndPosition = new Position() { X = 0, Y = 10 }
                        },
                        new Wall() 
                        {
                            StartPosition = new Position() { X = 0, Y = 10 },
                            EndPosition = new Position() { X = 0, Y = 0 }
                        }
                    }
                },
                AccessPoints = new List<AccessPoint>()
                {
                    new AccessPoint() { Location = new Position() { X = 2.5, Y = 2.5 }, MACAddress = "AC-81-12-73-F6-A7" },
                    new AccessPoint() { Location = new Position() { X = 7.5, Y = 7.5 }, MACAddress = "CC-52-AF-7B-29-9C" }
                }
            };


        }

    }
}
